<?php

declare(strict_types=1);

namespace app\validate;

use think\Validate;

class UsersVal extends Validate
{
    /**
     * 定义验证规则
     * 格式：'字段名' =>  ['规则1','规则2'...]
     *
     * @var array
     */
    protected $rule = [
        'nickname' => ['length' => '2,10'],
        'mobile' => ['require', 'value' => '/^1\d{10}$/'],
        'password' => ['require', 'length' => '6,12'],
        'email' => ['value' => '\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*'],
        'updatepwd' => ['length' => '6,12'],
    ];

    /**
     * 定义错误信息
     * 格式：'字段名.规则名' =>  '错误信息'
     *
     * @var array
     */
    protected $message = [
        'nickname.length' => '昵称必须2~10个字符',
        'mobile.require' => '手机号不可为空',
        'mobile.value' => '请输入正确的手机号码',
        'password.require' => '请输入密码',
        'password.length' => '密码必须6~12个字符',
        'email.value' => '请输入正确的邮箱',
        'updatepwd.length' => '密码必须6~12个字符',
    ];
    protected $scene = [
        'add' => ['nickname', 'mobile', 'password', 'email'],
        'edit' => ['nickname', 'mobile', 'updatepwd', 'email'],
        'login' => ['mobile', 'password'],
        'info' => ['nickname', 'email']
    ];
}
